<template>
  <view>
    <web-view :src="path"></web-view>
  </view>
</template>

<script>
import { getUrl } from "../../utils/constants";

export default {
  data() {
    return {
      prefix: getUrl() + "/pdf/web/viewer.html?file=",
      suffix: '.pdf',
      path: ""
    };
  },
  onLoad(){
    try {
      const value = uni.getStorageSync("pdf-url");
      if (value) {
        let data = JSON.parse(value);
        this.path = this.prefix + data.path + this.suffix;
        uni.setNavigationBarTitle({
          title: data.name
        })
      }else {
        this.$u.toast("出错啦！");
      }
    } catch (e) {
      console.log(e);
      this.$u.toast("出错啦！");
    }
  },
  onUnload(){
    uni.removeStorage({
      key: "pdf-url"
    })
  }
}
</script>

<style lang="scss">

</style>
